# -*- coding: utf-8 -*-
# @Time    : 2022/3/14 15:18
# @Author  : TangDagui
# @Email   : 3297364807@qq.com
# @File    : __init__.py.py
# @Software: PyCharm
from asyncio import sleep
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from aip import AipOcr

""" 你的 APPID AK SK """
APP_ID = '17547560'
API_KEY = 'N2AwQMQA1A7vStNefh54003L'
SECRET_KEY = '5ExplzDpeKs3AbXM8fkSbEGGybtx5Mab'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
browser = webdriver.Chrome(r"C:\Users\Administrator\PycharmProjects\pythonTask\mrTang\reptile\chromedriver.exe")
browser.implicitly_wait(10)
browser.get("https://sso.vpn.ccibe.edu.cn/cas/login")
browser.find_element_by_id("username").send_keys("20190784031")
browser.find_element_by_id("password").send_keys("072972")


def verificationCode():
    """ 读取图片 """
    url = "https://sso.vpn.ccibe.edu.cn/cas/captcha.jpg"
    """ 调用通用文字识别, 图片参数为远程url图片 """
    client.basicGeneralUrl(url)
    """ 如果有可选参数 """
    options = {}
    options["language_type"] = "CHN_ENG"
    options["detect_direction"] = "true"
    options["detect_language"] = "true"
    options["probability"] = "true"

    """ 带参数调用通用文字识别, 图片参数为远程url图片 """
    print(client.basicGeneralUrl(url, options))
    pass


verificationCode()


# while True:
#     time.sleep(1)
#     cookie_items = browser.get_cookies()
#     if int(len(cookie_items)) == 2:
#         break
#     # cookie_str = ""
#     # for item_cookie in cookie_items:
#     #     item_str = item_cookie["name"] + "=" + item_cookie["value"] + "; "
#     #     cookie_str += item_str
#     #     print(item_cookie)
#
# # browser.get("https://vpn.ccibe.edu.cn/") # 主页
# browser.get("https://alst.vpn.ccibe.edu.cn/login.aspx")  # 学生管理
# time.sleep(3)
# browser.find_elements_by_class_name("flex___2SZ0z")[1].click()
ActionChains(browser).key_down(Keys.CONTROL).send_keys("t").key_up(Keys.CONTROL).perform()
